package com.eop.managedBean;

import javax.faces.context.FacesContext;

import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.component.form.impl.UICombo;
import org.operamasks.faces.user.util.Browser;

import com.base.common.provider.CommonKeySelectItemProvider;

@ManagedBean(name = "eop_editEventBean", scope = ManagedBeanScope.REQUEST)
public class EditEventBean extends BaseEventBean {
	@Inject
	private FacesContext context;
	@Bind(id = "eventRangeB", attribute = "binding")
	protected UICombo eventRangeB_binding;
	@Bind(id = "eventRangeS", attribute = "binding")
	protected UICombo eventRangeS_binding;
	@SaveState
	private String first;

	@BeforeRender
	public void beforeRender(boolean isPostBack) throws Exception {
		if (!isPostBack) {
			id = context.getExternalContext().getRequestParameterMap()
					.get("id");
			if (!"".equals(id) && null != id) {
				event = eventService.getEventById(id);
				if (event != null) {
					eventRangeS_items = CommonKeySelectItemProvider
							.getDirectCommonKey(event.getEventRangeB(), false);
					this.getEventProperty(event);
				}
			}
		}
	}

	@Action(id = "eventRangeB", event = "onselect", immediate = true)
	public void changeEventRangeB() {
		first = eventRangeB_binding.getSubmittedValue().toString().trim();
		eventRangeS_items = CommonKeySelectItemProvider.getDirectCommonKey(
				first, false);
		eventRangeS = null;
		eventRangeS_binding.resetValue();
		eventRangeS_binding.repaint();

	}

	@Action(id = "save")
	public void save() {
		event = eventService.getEventById(id);
		this.setEventProperty();
		eventService.saveEvent(event);
		Browser
				.execClientScript("javascript:closeCenterLayoutTab('editEventTab')");
	}
}
